<template>
  <div>
    <el-table :data="joinclub" style="width: 100%" :default-sort = "{prop: 'state', order: 'descending'}">
      <el-table-column label="申请学生" width="120" prop="student">
      </el-table-column>
      <el-table-column label="所申社团" width="120" prop="club">
      </el-table-column>
      <el-table-column label="个人特长" width="300" prop="self">
      </el-table-column>
      <el-table-column label="申请理由" width="300" prop="why">
      </el-table-column>
      <el-table-column label="申请日期" width="140" sortable prop="date">
      </el-table-column>
      <el-table-column label="审核状态" width="120" sortable prop="state">
      </el-table-column>
      <el-table-column label="操作">
        <template
          slot-scope="scope"
          v-if="
            scope.row.state !== '审核通过' && scope.row.state !== '拒绝申请'
          "
        >
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >同意</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >拒绝</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from "axios";
// import { v4 as uuidv4 } from "uuid";
export default {
  name: "JoinClub",
  mounted() {
    this.all();
  },
  data() {
    return {
      info: "",
      deleteid: "",
      dialogFormVisible: false,
      joinclub: [],
      selectjoin: "",
    };
  },
  methods: {
    handleEdit(index, row) {
      this.deleteid = row.id;
      this.selectjoin = row;
      // console.log(index, row);
      axios
        .get("http://127.0.0.1/memberlist_yang/get", {
          params: {
            name: row.student,
          },
        })
        .then((res) => {
          console.log(res.data);
          this.info = res.data[0];
          axios
            .get("http://127.0.0.1/memberlist_yang/update", {
              params: {
                id: this.info.id,
                name: this.info.name,
                class: this.info.class,
                number: this.info.number,
                password: this.info.password,
                club: row.club,
              },
            })
            .then((res) => {
              console.log(res, "111");
              this.update();
            })
            .catch((err) => {
              console.log("获取数据失败" + err);
            });
        })
        .catch((err) => {
          console.log("获取数据失败" + err);
        });
    },
    handleDelete(index, row) {
      // console.log(index, row);
      this.selectjoin = row;
      axios
        .get("http://127.0.0.1/joinclub_yang/update", {
          params: {
            student: this.selectjoin.student,
            id: this.selectjoin.id,
            club: this.selectjoin.club,
            self: this.selectjoin.self,
            why: this.selectjoin.why,
            date: this.selectjoin.date,
            new: 1,
            studentid: this.selectjoin.studentid,
            state: "拒绝申请",
          },
        })
        .then(() => {
          this.all();
        })
        .catch((err) => {
          console.log("获取数据失败" + err);
        });
    },
    all() {
      //查找info表全部数据
      axios
        .get("http://127.0.0.1/joinclub_yang/all")
        .then((res) => {
          // console.log(res.data);
          this.joinclub = res.data;
          // console.log(this.joinclub);
        })
        .catch((err) => {
          console.log("获取数据失败" + err);
        });
    },
    update() {
      //修改操作
      axios
        .get("http://127.0.0.1/joinclub_yang/update", {
          params: {
            id: this.selectjoin.id,
            student: this.selectjoin.student,
            studentid: this.selectjoin.studentid,
            club: this.selectjoin.club,
            self: this.selectjoin.self,
            why: this.selectjoin.why,
            date: this.selectjoin.date,
            new: 0,
            state: "审核通过",
          },
        })
        .then(() => {
          this.all();
        })
        .catch((err) => {
          console.log("获取数据失败" + err);
        });
    },
  },
};
</script>

<style>
</style>